package com.atguigu.gulimall.gateway.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

@Configuration
public class CorsConfig {
    @Bean
    public CorsWebFilter corsWebFilter(){
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration config = new CorsConfiguration();

        config.addAllowedHeader("*");//允许携带哪些请求
        config.addAllowedMethod("*");//允许哪些方法跨域
        config.addAllowedOrigin("*");//允许哪些来源跨域
        config.setAllowCredentials(true);//是否允许携带cookie跨域

        source.registerCorsConfiguration("/**",config);
        return new CorsWebFilter(source);
    }
}
